package com.nju.edu.erp.web.controller;


import com.nju.edu.erp.auth.Authorized;
import com.nju.edu.erp.enums.Role;
import com.nju.edu.erp.model.vo.GetBusinessHistoryVO;
import com.nju.edu.erp.service.finance.BusinessHistoryService;
import com.nju.edu.erp.web.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/business-history")
public class BusinessHistoryController {
    private final BusinessHistoryService businessHistoryService;

    @Autowired
    public BusinessHistoryController(BusinessHistoryService businessHistoryService) {
        this.businessHistoryService=businessHistoryService;
    }
//1. 销售类单据（销售出货单，销售退货单） 2. 进货类单据（进货单，进货退货单） 3. 财务类单据（付款单，收款单，现金费用单，工资单）
    @PostMapping("/sale-sheet")
    @Authorized(roles = {Role.FINANCIAL_STAFF,Role.GM, Role.ADMIN})
    public Response getSaleSheet(@RequestBody GetBusinessHistoryVO getBusinessHistoryVO) {
        System.out.println(getBusinessHistoryVO.getBeginDate());
        System.out.println(getBusinessHistoryVO.getEndDate());
        System.out.println(getBusinessHistoryVO.getCName());
        System.out.println(getBusinessHistoryVO.getOperator());

        return Response.buildSuccess( businessHistoryService.getSaleSheet(getBusinessHistoryVO));
    }
    @PostMapping("/sale-returns-sheet")
    @Authorized (roles = {Role.FINANCIAL_STAFF,Role.GM, Role.ADMIN})
    public Response getSaleReturnsSheet(@RequestBody GetBusinessHistoryVO getBusinessHistoryVO) {
        System.out.println(getBusinessHistoryVO.getBeginDate());
        System.out.println(getBusinessHistoryVO.getEndDate());
        System.out.println(getBusinessHistoryVO.getCName());
        System.out.println(getBusinessHistoryVO.getOperator());
        return Response.buildSuccess( businessHistoryService.getSaleReturnsSheet(getBusinessHistoryVO));
    }

    @PostMapping("/purchase-sheet")
    @Authorized (roles = {Role.FINANCIAL_STAFF,Role.GM, Role.ADMIN})
    public Response getPurchaseSheet(@RequestBody GetBusinessHistoryVO getBusinessHistoryVO) {
        System.out.println(getBusinessHistoryVO.getBeginDate());
        System.out.println(getBusinessHistoryVO.getEndDate());
        System.out.println(getBusinessHistoryVO.getCName());
        System.out.println(getBusinessHistoryVO.getOperator());
        return Response.buildSuccess(businessHistoryService.getPurchaseSheet(getBusinessHistoryVO));
    }
    @PostMapping("/purchase-returns-sheet")
    @Authorized (roles = {Role.FINANCIAL_STAFF,Role.GM, Role.ADMIN})
    public Response getPurchaseReturnsSheet(@RequestBody GetBusinessHistoryVO getBusinessHistoryVO) {
        System.out.println(getBusinessHistoryVO.getBeginDate());
        System.out.println(getBusinessHistoryVO.getEndDate());
        System.out.println(getBusinessHistoryVO.getCName());
        System.out.println(getBusinessHistoryVO.getOperator());
        return Response.buildSuccess(businessHistoryService.getPurchaseReturnsSheet(getBusinessHistoryVO));
    }


}
